package com.meisupic.copyright.configuration;

import javax.validation.Validation;
import javax.validation.Validator;
import org.dozer.spring.DozerBeanMapperFactoryBean;
import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.authentication.encoding.Md5PasswordEncoder;

/**
 * creation wuxun
 *
 * @version V1.0
 * @Description: TODO
 * @date 2018/1/13 16:58
 */
@Configuration
public class CustomConfiguration {


  @Bean
  public DozerBeanMapperFactoryBean mapper() {
    return new DozerBeanMapperFactoryBean();
  }


  @Bean("hibernateValidator")
  public Validator initValidator() {
    return Validation.byProvider(HibernateValidator.class).configure().failFast(true)
        .buildValidatorFactory().getValidator();
  }

  @Bean
  public Md5PasswordEncoder md5PasswordEncoder() {
    return new Md5PasswordEncoder();
  }

  @Bean
  public ThreadPoolTaskExecutor initThreadPool() {
    ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
    threadPool.setCorePoolSize(50);
    threadPool.setKeepAliveSeconds(30000);
    threadPool.setMaxPoolSize(200);
    threadPool.setQueueCapacity(1000);
    return threadPool;
  }


}
